# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libvpx

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.0
pkgrel=2
pkgdesc="The VP8 Codec SDK (mingw-w64)"
arch=('any')
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-yasm")
url=('http://www.webmproject.org/')
source=(https://webm.googlecode.com/files/${_realname}-v${pkgver}.tar.bz2
    'configure.patch'
    'mingwstrtok.patch'
    'fix-dll-name.patch')
options=('strip' 'staticlibs')
md5sums=('14783a148872f2d08629ff7c694eb31f'
         '7c50751fc42580dca0ff277e83e3b55f'
         'ada9eb8f4b982a0cc1749aaab4153c11'
         '344d70d33ca2d30c83c0f816e548b084')

prepare() {
  cd ${srcdir}/$_realname-v$pkgver

  patch -Np1 -i ${srcdir}/configure.patch
  patch -Np1 -i ${srcdir}/mingwstrtok.patch
  patch -Np1 -i ${srcdir}/fix-dll-name.patch
}

build() {
  if [ ${MINGW_CHOST} = "i686-w64-mingw32" ]; then
    _targetarch="x86-win32-gcc"
  else
    _targetarch="x86_64-win64-gcc"
  fi
  mkdir -p $srcdir/build-$MINGW_CHOST
  cd "$srcdir/build-$MINGW_CHOST"
  ../$_realname-v$pkgver/configure \
    --prefix=${MINGW_PREFIX} \
    --target=${_targetarch} \
    --enable-vp8 \
    --enable-vp9 \
    --enable-runtime-cpu-detect \
    --enable-postproc \
    --enable-pic \
    --enable-shared \
    --disable-examples \
    --disable-docs \
    --disable-install-docs \
    --disable-install-srcs

  for _ff in *.mk; do
    sed -i "s/HAVE_GNU_STRIP=yes/HAVE_GNU_STRIP=no/g" $_ff
  done
  make -j1
}

package() {
  cd "${srcdir}/build-$MINGW_CHOST"
  make DIST_DIR="${pkgdir}${MINGW_PREFIX}" install

  #Move the hacked in shared libs to bin
  mkdir ${pkgdir}${MINGW_PREFIX}/bin
  mv ${pkgdir}${MINGW_PREFIX}/lib/libvpx.dll ${pkgdir}${MINGW_PREFIX}/bin/
  rm ${pkgdir}${MINGW_PREFIX}/lib/libvpx.dll.1*
}
